package com.aphrodite.io.sip.transaction;

import com.aphrodite.io.sip.message.Message;
import com.aphrodite.io.sip.provider.SipProvider;

/**
 * ACK client transaction should follow an INVITE client transaction within an
 * INVITE Dialog in a SIP UAC. The AckTransactionClient simply sends an ACK
 * request message and terminates.
 */
public class AckTransactionClient extends Transaction {

	/**
	 * the TransactionClientListener that captures the events fired by the
	 * AckTransactionClient
	 */
	TransactionClientListener transaction_listener;

	/** Creates a new AckTransactionClient. */
	public AckTransactionClient(SipProvider sip_provider, Message ack, TransactionClientListener listener) {
		super(sip_provider);
		request = new Message(ack);
		transaction_listener = listener;
		transaction_id = request.getTransactionId();
		log.info(this, "id: " + String.valueOf(transaction_id));
		log.info(this, "created");
	}

	/** Starts the AckTransactionClient and sends the ACK request. */
	public void request() {
		log.info(this, "start");
		sip_provider.sendMessage(request);
		changeStatus(STATE_TERMINATED);
		// if (transaction_listener!=null)
		// transaction_listener.onAckCltTerminated(this);
		// (CHANGE-040421) free the link to transaction_listener
		transaction_listener = null;
	}

	/** Method used to drop an active transaction. */
	public void terminate() {
		changeStatus(STATE_TERMINATED);
		// (CHANGE-040421) free the link to transaction_listener
		transaction_listener = null;
	}

}
